package com.chen.client;

import com.alibaba.fastjson.parser.ParserConfig;
import com.chen.cglib.RpcMethodInterceptor;
import com.chen.filter.Filter;
import com.chen.handler.RpcInvocationHandler;
import net.sf.cglib.proxy.Enhancer;

import java.lang.reflect.Proxy;

public final class RpcCli {
    static {
        ParserConfig.getGlobalInstance().addAccept("com.chen");
    }

    public static <T> T create(final Class<T> serviceClass, final String url, Filter...filters){
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(serviceClass);
        enhancer.setCallback(new RpcMethodInterceptor(serviceClass, url, filters));
        return (T)enhancer.create();
        //return (T) Proxy.newProxyInstance(RpcCli.class.getClassLoader(),new Class[]{serviceClass},new RpcInvocationHandler(serviceClass,url,filters));
    }

}
